[#ftl]
[#--include "../../util.ftl"/--]			
[@define "agile.dijit.MenuBarItem" "agile._Component,agile._Resizable,agile.dijit._PopupSubMenuMixin" "InlineEditBox=dijit/InlineEditBox,MenuBarItem=dijit/MenuBarItem"]
	widgetName:"MenuBarItem"
	[#assign templateString][#compress]			
		<div class="agileComponent agileMenuBarItem" style="align:left">
			<div data-dojo-type='dijit/InlineEditBox' data-dojo-attach-point='label' data-dojo-props='style:"width:{style.width}",width:"{style.width}"'>{parameters.label}</div>				 
			<div data-dojo-attach-point="containerNode"></div>
		</div>
	[/#compress][/#assign]
	,templateString:"${templateString?js_string}"
	,resizeAxis:"x"	
	,styleConstraints:agile.delegate(agile._Component.prototype.styleConstraints,{
		"left": {ignore:function(widget,sourceType){ return sourceType !="agile";}}
		,"top": {_ignore:true}
	    ,"height":{_ignore:true}
	    ,"width":{_ignore:true}
	    ,"position":{_ignore:true}
	    ,"z-index":{_ignore:true}
	})
	,attributes:agile.delegate(agile._Component.prototype.attributes,{
		label:lang.mixin({},agile.TextMetadata,{
			label:"i18n_label",
			onValueChange:function(/*widget*/widget,/*String*/name,/*Object*/value){					
				widget.label.set("value",value);
				widget.metadata("parameters."+name,value);
			}				
		})			
//			,accelKey:lang.mixin({},agile.TextMetadata,{
//				dojo:false
//				,onValueChange:function(/*widget*/widget,/*String*/name,/*Object*/value){								
//					widget.metadata(name,value);
//					//widget.accelKey.set("value",value);
//				}				
//			})
		,isSubMenu:lang.mixin({},agile.BooleanMetadata,{_hidden:true,_ignore:true})
		,moveable:lang.mixin({},agile.BooleanMetadata,{_hidden:true,_ignore:true})
	})	
	,events:agile.delegate(agile._Component.prototype.events,{
			"onClick": {_ignore:false}
	})
	,initDefaultMetadata:function(){
		this.metadata("parameters.label","");
		this.metadata("parameters.disabled",false);					
		this.metadata("style.position",null);
		this.metadata("style.width","50px");
		this.metadata("parameters.isSubMenu",true);
		this.metadata("dojoDeclaredClass","dijit/MenuBarItem");
	}
//	,constructor: function(){
//		agile.requireX("dijit.MenuBarItem");
//		agile.requireX("dijit.InlineEditBox");	
//	 }
//	
	,init:function(){		
		if(this._initMenuBarItem){return;}
		this._initMenuBarItem = true;
		
		this.label.watch("value",lang.hitch(this,function(name,oldValue,newValue){
			topic.publish("agile.widget.changed",this.category,"label",newValue);					
			this.metadata("parameters.label",newValue);
		}));
		
		aspect.after(this.label,"edit",lang.hitch(this,function(){
			if(this.metadata("parameters.isSubMenu")){
				this.showSubMenu(true);
			}
			//hide all siblings
			var siblings = this.parent.getChildren();
			for(var i = 0; i < siblings.length; i++){
				if(siblings[i] != this && siblings[i].metadata("parameters.isSubMenu")){					
					siblings[i].showSubMenu(false);
				}
			}
		}));

		lang.mixin(this,{onDeselected:function(event){},onSelected:function(event){}});	
		
		on(this.domNode,mouse.enter,lang.hitch(this,function(evt){								
			this.parent.showControlButtons(this,evt);
		}));
	}
	,removeChild:function(child){
		//can not remove
	}
	,getPreferredSize:function(){
		return {w:this.dimension.width+5,h:this.dimension.height};
	}
	,getPopupMenuPositon:function(){
		return "below";
	}
	,getResizableTargetContainer:function(){
		return this.label.domNode;
	}
	,getToolbarAnchorNode:function(){
		return this.domNode;
	}
	,_getDelegatePrototype:function(){
		return MenuBarItem.prototype;
	}
[/@]	
